import Opt from '@/components/dt/info/Opt.js'
import organizationOpt from '@/biz/option/organization.js'
import toolMgr from '@/biz/base/tool.js'
import houseOpt from '@/biz/option/house.js'
let _this = null
class SearchOpt extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '目标年份',
        placeholder: '全部',
        key: 'year',
        date: {
          clearable: false,
          type: 'year',
          disabled: (date) => {
            const disabledDate = date.getFullYear()
            const currentYear = new Date().getFullYear() + 1
            return !(disabledDate >= currentYear - 3 && disabledDate <= currentYear)
          }
        },
        change: (res) => {
          _this.searchInfo.month = ''
        }
      },
      {
        title: '目标月份',
        placeholder: '全部',
        key: 'month',
        date: {
          clearable: false,
          type: 'month',
          format: 'MM',
          disabled: (date) => {
            const year = _this.searchInfo.year
            const currentYear = new Date().getFullYear()
            if (currentYear == year) {
              // let currentDate = new Date() // 获取当前日期对象
              // currentDate.setMonth(currentDate.getMonth() + 1) // 增加一个月
              // let newDate = currentDate.getTime()
              // return date.valueOf() > newDate
              const currentDate = new Date()
              currentDate.setHours(23, 59, 59, 0)
              const currentMonthEndDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 2, 0)
              return date > currentMonthEndDate
            } else if (currentYear < year) {
              // return date.valueOf() > 2
              return date.getMonth() !== 0
            }
          }
        }
      },
      {
        title: '目标筛选',
        placeholder: '全部',
        key: 'headCodes',
        select: {
          options: _this.searchTarget,
          multiple: true,
          maxTagCount: 1
        }
      },

      {
        title: '所属案场',
        placeholder: '请输入案场名称',
        key: 'housesName',

        input: {
          clearable: true
        }
      }
      // houseOpt.create({
      //   to: (info) => {
      //     return {
      //       buildingId: info.housesId
      //     }
      //   }
      // })
    ]
  }
}

export default SearchOpt
